package timeslice
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	import flash.utils.Dictionary;
	
	import globals.$root;
	
	import org.musince.util.DictionaryUtilPlus;
	
	import slices.TimeSlice;
	
	public class DisplayMainMenu extends TimeSlice
	{
		private var _mc:MovieClip; 
		private var _hit:MovieClip;
		private var _itemCount:int = 2;
		private var _items:Vector.<MovieClip> = new Vector.<MovieClip>(2);
		private var _selecting:int = -1;
		private var _selectFilters:Array = [new GlowFilter(0x76EBD9, 1, 130, 30, 3)];
		private var _notSelectFilters:Array = [new GlowFilter(0x65AAF8, 1, 14, 14)];
		
		public function DisplayMainMenu()
		{
			super();
		}
		
		override public function onStart():void {
			$root.removeChildren();
			$root.stage.color = 0xFFFFFF;
			_mc = DictionaryUtilPlus.getFirst(getInput(PORT_RESOURCE) as Dictionary) as MovieClip;
			_hit = _mc.hitMain as MovieClip;
			_hit.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
			_hit.addEventListener(MouseEvent.CLICK, onClick);
			_items[0] = _mc.btnNewGame;
			_items[1] = _mc.btnContinue;
			select(0);
			$root.addChild(_mc);
		}
		
		private function onMouseMove(e:MouseEvent):void {
			var index:int = Math.max(0, Math.min(1, e.localY * _itemCount / _hit.height));
			select(index);
		}
		
		private function onClick(e:MouseEvent):void {
			isEnd = true;	
		}
		
		private function select(v:int):void {
			if (v == _selecting) return;
			for (var i:int = 0; i < _items.length; i++) {
				if (i != v) {
					_items[i].filters = _notSelectFilters;
					_items[i].scaleX = _items[i].scaleY = 1;
				}
			}
			_items[v].filters = _selectFilters;
			_items[v].scaleX = _items[v].scaleY = 1.5;
		}
		
		
	}
}